package com.maolong.controller.item;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maolong.entity.domain.Item;
import com.maolong.entity.format.Code;
import com.maolong.entity.format.RespResult;
import com.maolong.service.IItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/itemplus")
public class WorkItemController {
    @Autowired
    IItemService itemService;

    /**
     * 查询商品信息，可以接收商品名称，特定查询，若无，查全部
     * 完成了分页功能
     * @param name
     * @return
     */
    @GetMapping
    public RespResult productList(@RequestParam(value = "name",required = false)String name) {
        List<Item> list;
        if(name == null||"".equals(name)) {
            list = itemService.list();
        }else{
            QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
            queryWrapper.like("name",name);
            list=itemService.list(queryWrapper);
        }
        log.info("查询到的数据是{}",list);
        System.out.println(list);
        return new RespResult(Code.ITEM_SELECT_OK,list,"查询成功");
    }

}
